/*
 * $Id: ValidationManager.java 122 2009-05-12 15:54:07Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.gui.deltagui.validation;

import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

import deltadesk.gui.deltagui.layout.LayoutContainer;

/**
 * ValidationManager.
 * 
 * @author Andreas Meyer
 * @version $Revision: 122 $
 */
public class ValidationManager {
	
	private static final ValidationManager INSTANCE;
	
	/** The validation thread. */
	private final ValidatorThread validator;
	
	/** The queue for invalidated layout container. */
	private final Queue<LayoutContainer> queue;


	static {
		INSTANCE = new ValidationManager();
	}
	
	/**
	 * Construct the manager.
	 * 
	 */
	private ValidationManager() {

		queue = new ArrayBlockingQueue<LayoutContainer>(100);
		validator = new ValidatorThread(queue);
		
		validator.start();
	}
	
	/**
	 * Return the singleton instance.
	 * 
	 * @return
	 */
	public static ValidationManager getInstance() {
		return INSTANCE;
	}
	
	/**
	 * Invalidate the layout container.
	 * 
	 * @param c
	 */
	public void invalidate(final LayoutContainer c) {
		queue.offer(c);
	}
	
	/**
	 * Stop the validation manager.
	 */
	public void stop() {
		validator.setRunning(false);
	}

}
